/*
 * @Author: xmily
 * @Date: 2021-12-20 19:20:53
 * @LastEditors: xmily
 * @LastEditTime: 2022-08-24 22:14:33
 * @FilePath: \glxxapi\models\Notice\notice.js
 * @Description: 
 * 
 * Copyright (c) 2022 by xmily/mxthink.com.cn, All Rights Reserved. 
 */
//家校通知表
var mongoose = require('../../cfg/dbconfig.js')

var noticeSchema = new mongoose.Schema({
    title:String,
    publictime:String,
    content:String,
    backdesc:String,
    noticePicUrl:Array ,
    signXY:Array ,
    signid:Number,
    datetime:Date,
    cover:Boolean,
},{collection:'notice'})

//获取所有通知列表
noticeSchema.statics.GetByAggregate=async function(query){
    let result= await this.aggregate(
        query
    )
    return result
}


noticeSchema.statics.GetByQuery=async function(query,sort){
    let result= await this.find(query).sort(sort).exec();
    return result
}


noticeSchema.statics.Save=async function(doc){
    let obj=new this(doc);
    if(doc._id){
        obj.isNew=false;
    }
    let res=await obj.save();
    return res;
}

noticeSchema.statics.Update=async function(doc){
    let id=doc._id;
    delete doc._id;
    let result = await this.updateOne({ _id: id }, doc).exec();
    return result
}

noticeSchema.statics.GetOneByQuery=async function(query){
    let result= await this.findOne(query).exec();
    return result
}


module.exports = mongoose.model('notice', noticeSchema)